package main

import (
	"fmt"
	"github.com/chromedp/chromedp"

	"time"
)



func googleSearch(q, text string, site, res *string) chromedp.Tasks {
	var buf []byte
	sel := fmt.Sprintf(`//a[text()[contains(., '%s')]]`, text)
	return chromedp.Tasks{
		chromedp.Navigate(`https://www.sohu.com`),
		chromedp.Sleep(2 * time.Second),
		chromedp.WaitVisible(`#hplogo`, chromedp.ByID),
		chromedp.SendKeys(`#lst-ib`, q+"", chromedp.ByID),
		chromedp.WaitVisible(`#res`, chromedp.ByID),
		chromedp.Text(sel, res),
		chromedp.Click(sel),
		chromedp.Sleep(2 * time.Second),
		chromedp.WaitVisible(`#footer`, chromedp.ByQuery),
		chromedp.WaitNotVisible(`div.v-middle > div.la-ball-clip-rotate`, chromedp.ByQuery),
		chromedp.Location(site),
		chromedp.Screenshot(`#testimonials`, &buf, chromedp.ByID),
		//chromedp.ActionFunc(func(context.Context, cdp.Executor) error {
		//	return ioutil.WriteFile("testimonials.png", buf, 0644)
		//}),
	}
}
